      SUBROUTINE PARSE ( WORK, LW, TOKE, NTOKE, ERR )
C*
C*                  *******************************
C*                  *******************************
C*                  **                           **
C*                  **           PARSE           **
C*                  **                           **
C*                  *******************************
C*                  *******************************
C*
C*     SUBPROGRAM :
C*          PARSER
C*
C*     AUTHOR :
C*          ART RAGOSTA
C*          MS 207-5
C*          AMES RESEARCH CENTER
C*          MOFFETT FIELD, CALIF   94035
C*          (415) 694-5578
C*
C*     PURPOSE :
C*          PARSE THE STRING INTO AN ARRAY OF TOKENS.
C*          NOTE: THE ONLY VALID SYMBOLS ARE -
C*                   UNITS,   EXPONENTS,   '*',   '^',  '/',  '(',  AND  ')'
C*
C*     METHODOLOGY :
C*          NA
C*
C*     INPUT ARGUMENTS :
C*          WORK  - THE STRING TO BE PARSED
C*
C*     OUTPUT ARGUMENTS :
C*          TOKE  - THE ARRAY OF TOKENS
C*          NTOKE - THE NUMBER OF TOKENS FOUND
C*          ERR   - SET TRUE IF AN ERROR IS UNCOVERED
C*
C*     INTERNAL WORK AREAS :
C*          NONE
C*
C*     COMMON BLOCKS :
C*          NONE
C*
C*     FILE REFERENCES :
C*          NONE
C*
C*     SUBPROGRAM REFERENCES :
C*          LENGTH
C*
C*     ERROR PROCESSING :
C*          CHECKS FOR INVALID CHARACTERS.
C*          DISALLOWS EXPONENTS GREATER THAN 99.
C*
C*     TRANSPORTABILITY LIMITATIONS :
C*          NONE
C*
C*     ASSUMPTIONS AND RESTRICTIONS :
C*          NONE
C*
C*     LANGUAGE AND COMPILER :
C*          ANSI FORTRAN 77
C*
C*     VERSION AND DATE :
C*          VERSION I.0      7-FEB-85
C*
C*     CHANGE HISTORY :
C*           7-FEB-85    INITIAL VERSION
C*
C***********************************************************************
C*
      CHARACTER *(*) WORK
      CHARACTER *6 TOKE(1)
      LOGICAL ERR
C
      I     = 1
      NTOKE = 0
C
C --- ALL UNITS BEGIN WITH A CHARACTER
C
100   IF ((WORK(I:I) .GE. 'A') .AND. (WORK(I:I) .LE. 'Z')) THEN
         NTOKE = NTOKE + 1
         INT = 1
         TOKE(NTOKE) = ' '
110      IF (INT .LE. 6) THEN
            TOKE(NTOKE)(INT:INT) = WORK(I:I)
            INT = INT + 1
         ENDIF
         I = I + 1
         IF (I .GT. LW) GO TO 1000
         IF ((WORK(I:I) .GE. 'A') .AND. (WORK(I:I) .LE. 'Z')) GO TO 110
C
C --- NUMBERS USED AS EXPONENTS
C
      ELSE IF ((WORK(I:I) .GE. '0') .AND. (WORK(I:I) .LE. '9')) THEN
         NTOKE = NTOKE + 1
         INT   = 1
         TOKE(NTOKE) = ' '
210      TOKE(NTOKE)(INT:INT) = WORK(I:I)
         INT   = INT + 1
         I     = I + 1
         IF (I .GT. LW) GO TO 1000
         IF ((WORK(I:I) .GE. '0') .AND. (WORK(I:I) .LE. '9')) GO TO 210
         IF (INT .GT. 2) THEN
            ERR = .TRUE.
            RETURN
         ENDIF
C
C --- OPERATORS ARE   (  )  *  /  ^
C
      ELSE IF ((WORK(I:I) .EQ. '(') .OR. (WORK(I:I) .EQ. ')') .OR.
     $         (WORK(I:I) .EQ. '*') .OR. (WORK(I:I) .EQ. '/') .OR.
     $         (WORK(I:I) .EQ. '^')) THEN
         NTOKE = NTOKE + 1
         TOKE(NTOKE) = WORK(I:I)
         I = I + 1
C
C --- NO OTHER CHARACTERS ARE VALID
C
      ELSE
         ERR = .TRUE.
         RETURN
      ENDIF
      IF (I .LE. LW) GO TO 100
1000  RETURN
      END
C
C---END PARSE
C
